package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.YunjiayiNotice;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiNoticeMapper {
    @Delete({
        "delete from yunjiayi_notice",
        "where notice_id = #{noticeId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer noticeId);


    /*通过UID删除*/
    @Delete({
            "delete from yunjiayi_notice",
            "where formuserId = #{formuserId,jdbcType=INTEGER}"
    })
    int deleteByUID(Integer formuserId);

    @Insert({
        "insert into yunjiayi_notice (notice_id, create_time, ",
        "content, formuserId, ",
        "touserId, delete_time, ",
        "isAgree)",
        "values (#{noticeId,jdbcType=INTEGER}, now(), ",
        "#{content,jdbcType=VARCHAR}, #{formuserid,jdbcType=INTEGER}, ",
        "#{touserid,jdbcType=INTEGER}, now(), ",
        "#{isagree,jdbcType=INTEGER})"
    })
    int insert(YunjiayiNotice record);

    @Select({
        "select",
        "notice_id, create_time, content, formuserId, touserId, delete_time, isAgree",
        "from yunjiayi_notice",
        "where notice_id = #{noticeId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="notice_id", property="noticeId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="formuserId", property="formuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="touserId", property="touserid", jdbcType=JdbcType.INTEGER),
        @Result(column="delete_time", property="deleteTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="isAgree", property="isagree", jdbcType=JdbcType.INTEGER)
    })
    YunjiayiNotice selectByPrimaryKey(Integer noticeId);

    @Select({
        "select",
        "notice_id, create_time, content, formuserId, touserId, delete_time, isAgree",
        "from yunjiayi_notice"
    })
    @Results(id = "NoticeMap",value = {
        @Result(column="notice_id", property="noticeId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="content", property="content", jdbcType=JdbcType.VARCHAR),
        @Result(column="formuserId", property="formuserid", jdbcType=JdbcType.INTEGER),
        @Result(column="touserId", property="touserid", jdbcType=JdbcType.INTEGER),
        @Result(column="delete_time", property="deleteTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="isAgree", property="isagree", jdbcType=JdbcType.INTEGER)
    })
    List<YunjiayiNotice> selectAll();

    /*通过fromId查询*/
    @Select("select * from yunjiayi_notice where touserId=#{uId}")
    @ResultMap("NoticeMap")
    List<YunjiayiNotice>getNotic(@Param("uId")Integer uId);



    @Update({
        "update yunjiayi_notice",
        "set",
          "content = #{content,jdbcType=VARCHAR},",
          "formuserId = #{formuserid,jdbcType=INTEGER},",
          "touserId = #{touserid,jdbcType=INTEGER},",
          "delete_time = now(),",
          "isAgree = #{isagree,jdbcType=INTEGER}",
        "where notice_id = #{noticeId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiNotice record);
}